<template>
	<view class="collect">
		<view class="top">
			<view class="nav" :data-i="0" @click="changeType">
				全部
				<view class="line" v-if="type==0">
					
				</view>
			</view>
			<view class="nav" :data-i="1" @click="changeType">
				待付款
				<view class="line" v-if="type==1">
					
				</view>
			</view>
			<view class="nav" :data-i="2"  @click="changeType">
				待核销
				<view class="line" v-if="type==2">
					
				</view>
			</view>
			<view class="nav" :data-i="3"  @click="changeType">
				已使用
				<view class="line" v-if="type==3">
					
				</view>
			</view>
		</view>
		<view class="list" v-for="v in list" :key="v.id" :data-id="v.id" @click="toDetails">
			<view class="l_left">
				<view class="l_img">
					<image v-if="v.line.image" :src="http+v.line.image" mode=""></image>
				</view>
				<view class="l_text">
					<view class="">
						{{v.line.title}}
					</view>
					<view class="t_bottom">
						{{v.spec}}
					</view>
				</view>
			</view>
			<view class="l_right">
				<view class="type">
					{{arr[v.status]}}
				</view>
				<view class="money">
					￥{{v.oneprice}}
				</view>
				<view class="num">
					<text>x</text>{{v.number}}
				</view>
			</view>
		</view>
		<view class="kong" v-if="list==''">
			<view class="kong_img">
				<image src="../../static/mine/kong.png" mode=""></image>
			</view>
			<view class="kong_text">
				还没有订单，赶快去下单吧
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:0,
				mid:0,
				arr:['已取消','待付款','待核销','已使用','申请退款','已退款','拒绝退款','延时退款'],
				http:this.$http,
				list:[]
			}
		},
		onLoad() {
			if(uni.getStorageSync('user')){
				this.mid = uni.getStorageSync('user').id
				this.$post('user/lineOrderList',{
					mid:this.mid,
					page:1,
					status:this.type
				}).then(res=>{
					// console.log(res)
					if(res.code==0){
						this.list = res.data.list
					}
					if(res.code== -3){
						uni.showToast({
							title:'用户不存在请重新登录',
							icon:'none',
							mask:true
						})
						uni.clearStorage()
						setTimeout(()=>{
							uni.switchTab({
								url:'../index/index'
							})
						},1200)
					}
					if(res.code== -4){
						uni.showToast({
							title:'用户已被禁用',
							icon:'none',
							mask:true
						})
						// uni.clearStorage()
						setTimeout(()=>{
							uni.switchTab({
								url:'../index/index'
							})
						},1200)
					}
				})
			}
		},
		onShow() {
			this.page = 1
			if(uni.getStorageSync('user')){
				this.mid = uni.getStorageSync('user').id
				this.$post('user/lineOrderList',{
					mid:this.mid,
					page:1,
					status:this.type
				}).then(res=>{
					// console.log(res)
					if(res.code==0){
						this.list = res.data.list
					}
				})
			}
		},
		onReachBottom() {
			if(this.page<this.allpage){
				this.page++
				this.$post('user/lineOrderList',{
					mid:this.mid,
					page:this.page,
					status:this.type
				}).then(res=>{
					// console.log(res)
					if(res.code==0){
						this.list = this.list.concat(res.data.list)
						this.allpage = res.data.allpage
					}
				})
			}
		},
		onShareAppMessage(e) {
			return {
				title: '',
				path: '/pages/index/index'
			}
		},
		methods: {
			changeType(e){
				// // console.log(e.currentTarget.dataset.i)
				this.type = e.currentTarget.dataset.i
				this.$post('user/lineOrderList',{
					mid:this.mid,
					page:1,
					status:this.type
				}).then(res=>{
					// console.log(res)
					if(res.code==0){
						this.list = res.data.list
					}
				})
			},
			toDetails(e){
				// console.log(e.currentTarget.dataset.id)
				let id = e.currentTarget.dataset.id
				uni.navigateTo({
					url:'details2?id='+id
				})
			}
		}
	}
</script>

<style lang="less">
	image{
		width: 100%;
		height: 100%;
	}
	.collect{
		.kong{
			margin-top: 160rpx;
			.kong_img{
				width: 450rpx;
				height: 287rpx;
				margin: 0 auto;
			}
			.kong_text{
				text-align: center;
				font-weight: 500;
				color: #666666;
				font-size: 34rpx;
			}
		}
		.top{
			display: flex;
			padding: 18rpx 50rpx;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;
			.nav{
				font-size: 28rpx;
				font-weight: 700;
				color: #333333;
				position: relative;
				padding: 6rpx 40rpx;
				.line{
					position: absolute;
					bottom: 0;
					left: 50%;
					transform: translate(-50%,0);
					width: 28rpx;
					height: 4rpx;
					opacity: 1;
					background: #fcc521;
					border-radius: 2rpx;
				}
			}
		}
		.list{
			width: 100%;
			background-color: #FFFFFF;
			padding: 12rpx 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 10rpx;
			box-sizing: border-box;
			.l_left{
				display: flex;
				// align-items: center;
				.l_img{
					width: 143rpx;
					height: 139rpx;
				}
				.l_text{
					font-size: 28rpx;
					color: #333333;
					font-weight: 700;
					margin-left: 14rpx;
					padding-top: 20rpx;
					box-sizing: border-box;
					width: 350rpx;
					.t_bottom{
						color: #666666;
						font-size: 22rpx;
						margin-top: 20rpx;
					}
				}
			}
			.l_right{
				text-align: right;
				.type{
					font-size: 24rpx;
					color: #fcc521;
					font-weight: 500;
				}
				.money{
					font-size: 34rpx;
					font-weight: 500;
					color: #333333;
				}
				.num{
					font-size: 28rpx;
					font-weight: 500;
					color: #666666;
					text{
						font-size: 26rpx;
					}
				}
			}
			
		}
	}
</style>
